var util = require('../../utils/util.js')
var app = getApp();
Page({
  data: {
    phone: '',
    name: '',
    sex: '',
    fresh_year: '',
    arr: ['专科', '本科', '硕士', '博士', '博士后'],
    objectArray: [
      {
        id: 0,
        name: '专科'
      },
      {
        id: 1,
        name: '本科'
      },
      {
        id: 2,
        name: '硕士'
      },
      {
        id: 3,
        name: '博士'
      },
      {
        id: 4,
        name: '博士后'
      }
    ],
    degree: 1,
    wx_id: 'sho',
    birthday: '1990-08-12',
    intro: '我是刘德华',
    src: '',
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    if(options){
      this.setData({
        "phone": options.phone,
        "name": options.name,
        "sex": options.sex,
        "fresh_year": options.fresh_year,
        "degree": util.getDegreeIndex(options.degree)
      });
    }
  },
  bindinput_fresh_year:function(e){
    this.setData({ fresh_year: e.detail.value})
  },
  bindDegreeChange: function (e) {
    this.setData({ degree: e.detail.value })
  },
  bindBirthdayChange: function (e) {
    this.setData({ birthday: e.detail.value })
  },
  bindinput_wx_id: function (e) {
    this.setData({ wx_id: e.detail.value })
  },
  bindinput_intro: function (e) {
    this.setData({ intro: e.detail.value })
  },
  upload_img:function(){
    var that = this;
    wx.chooseImage({
      count: 1,
      sizeType: ['original', 'compressed'],
      sourceType: ['album', 'camera'],
      success(res) {
        var tempFilePaths = res.tempFilePaths
        that.setData({ src: tempFilePaths[0]});
      }
    })
  },
  save_edit_details:function(){
    var post_data = {
      'phone':this.data.phone,
      'fresh_year': this.data.fresh_year,
      'degree': this.data.degree,
      'wx_id': this.data.wx_id,
      'birthday': this.data.birthday,
      'intro': this.data.intro,
      'flag': 'update',
    }
    // console.log(JSON.stringify(post_data));
      var that = this; 
      wx.uploadFile({
        url: app.globalData.query_ip + '/wx_register',
        filePath: this.data.src,
        method: 'POST',
        name: 'file',
        formData: post_data,
        success(res) {
          if(!res.data){
            wx.showToast({
                title:  '修改成功',
                icon:  'success',
                duration:  2000
          });
          }else{
            wx.showToast({
              title: '修改失败',
              icon: 'loading',
              duration: 2000
            });
          }
        }
      })
  }
})